#!/bin/sh

if [ -e config ]; then
	source config
else
	exit -1
fi

###### 如果文件丢失，就新建一个空文件

if [ -e mingju.md ]; then 
	find . -mnewer mingju.md | grep $tag |grep ".md" > tmp.list
else
	touch mingju.md
fi


if [ $? -ne 0 ]; then 
	echo $bookname "名句 OK"
	rm -f tmp.list
	exit 0
fi

echored $bookname 

rm -f tmp.list

rm -f mingju.md

#touch mingju.md

for files in `ls  -l |sed -e '/^l/d'|awk '{print $NF}'|grep ^$tag`
do 

	getmingju $files  | sed -e "/^</d" >>mingju.md

done

TMPFILE=`echo $0|awk -F/ '{print $NF}'``date|sed -e "s/ //g"`.tmp

sed -e "/^ *$/d" mingju.md|sed -e "/^$/d">$TMPFILE

mv $TMPFILE mingju.md 

# 删除只有一个英文字母的句子。

counter=1

while IFS= read -r line; 
do
	if echo $line | grep -q -e "^#### " -e "^### " -e "^## "; then 
		echo $line
		echo ""
		continue
	else
		printf "%04d. " $counter 

		echo $line

		echo ""

		((counter=counter+1))
	fi

done < mingju.md >$TMPFILE

mv $TMPFILE mingju.md
